import React from "react";
import {HashRouter, Redirect, Route, Switch} from "react-router-dom";
import Login from "../views/login/Login";
import NewsSandBox from "../views/newssandbox/NewsSandBox";

export default function IndexRouter() {
    return (
        <HashRouter>
            {/* 不要随意开启严格匹配模式，有些时候开启会导致无法继续匹配二级路由 */}
            {/*<Route exact={true} path="/login" component={Login}/>*/}
            {/*<Route exact={true} path="/" component={NewsSandBox}/>*/}
            <Switch>
                <Route path="/login" component={Login}/>
                <Route path="/" component={NewsSandBox}/>
                <Route path="/" render={() => {
                    return (
                        localStorage.getItem("token") ? <NewsSandBox/> : <Redirect to="/login"/>
                    )
                }}/>
            </Switch>
        </HashRouter>
    )
}
